package com.heima.admin.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.admin.service.WmChannelService;

import com.heima.model.wemedia.dtos.AdChannel;
import com.heima.model.wemedia.dtos.ChannelDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 频道信息表 前端控制器
 * </p>
 *
 *
 * @author itheima
 *
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService  wmChannelService;


    @GetMapping("/channels")
    public ResponseResult findAll(){
        return  ResponseResult.okResult(wmChannelService.list());
    }
    /**
     * 新增频道
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return wmChannelService.saveChannel(adChannel);
    }

    /**
     * 频道名称模糊分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDto dto) {
        return wmChannelService.getChannelList(dto);
    }

    /**
     * 修改频道--无引用频道可禁用
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return wmChannelService.updateChannel(adChannel);
    }

    /**
     * 删除频道--禁用频道才可以删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Integer id) {
        return wmChannelService.delChannel(id);
    }
}

